﻿using GN.Pay.TradeChannel.DefaultImpl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GN.Pay.Utils;
using GN.Pay.Utils.Security;

namespace GN.Pay.TradeChannel.WeiXin.Response
{
    /// <summary>
    /// app支付响应
    /// </summary>
    [Serializable]
    class AppPayResponse : PayResponse
    {
        public AppPayResponse(string xml)
            : base(xml)
        {
        }

        /// <summary>
        /// 转为结果
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public override ITradePayApplyResult ToResult(WeiXinConfigure config)
        {
            ToResultCheck(config);
            SignDictionary sign = new SignDictionary();
            sign["appid"] = this.AppId;
            sign["partnerid"] = this.Mch_Id;
            sign["prepayid"] = this.Prepay_Id;
            sign["package"] = "Sign=WXPay";
            sign["noncestr"] = Guid.NewGuid().ToString("N");
            sign["timestamp"] = DateTimeUtils.CurrentTimeStampSeconds.ToString();
            string content = sign.UrlLinkString() + "&key=" + config.ConfigureInfo.Key;
            sign["sign"] = Md5Utils.Sign(content, config.Encoding).ToUpperInvariant();
            return new TradePayApplyResult(Prepay_Id, "", sign.ToJson(true), TradePayApplyResultCallType.App_Json);

            //ToResultCheck(config);
            //SignDictionary sign = new SignDictionary();
            //sign["appid"] = this.AppId;
            //sign["partnerid"] = this.Mch_Id;
            //sign["prepayid"] = this.Prepay_Id;
            //sign["package"] = "WAP";
            //sign["noncestr"] = Guid.NewGuid().ToString("N");
            //sign["timestamp"] = DateTimeUtils.CurrentTimeStampSeconds.ToString();
            //string content = sign.UrlLinkString() + "&key=" + config.ConfigureInfo.Key;
            //sign["sign"] = Md5Utils.Sgin(content, config.Encoding).ToUpperInvariant();
            //return new TradePayApplyResult(Prepay_Id, "", "weixin://wap/pay?" +  sign.UrlLinkString(), TradePayApplyResultCallType.App_Url);
        }
    }
}
